/**
 * 
 */
package tk.sunlatus.project.interface4web.action;

import java.util.List;

import org.apache.log4j.Logger;

import tk.sunlatus.project.common.domain.Page;
import tk.sunlatus.project.config.ConfigurationManager;
import tk.sunlatus.project.usermanage.domain.User;
import tk.sunlatus.project.usermanage.web.Service4WebUI;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author sunlotus
 * 
 */
public class UserAction extends ActionSupport {

    private static final Logger LOGGER = Logger.getLogger(UserAction.class);

    private User user = null;

    private List<User> userList = null;

    private Service4WebUI service4WebUI = null;

    private ConfigurationManager configurationManager = null;

    private Page page = null;

    private static final long serialVersionUID = 5127468051626970235L;

    /**
     * 方法描述：查询用户信息
     * 
     * @return
     */
    public String queryUserInfo() {
        LOGGER.debug("enter query userInfo");
        String userID = "test";
        if (user != null && user.getUserID() != null) {
            userID = user.getUserID();
        }
        user = getService4WebUI().querUserByID(userID);
        LOGGER.debug("exit query userInfo");
        return SUCCESS;
    }

    /**
     * 方法描述： 查询用户列表
     */
    public String queryUserList() {
        LOGGER.debug("enter query queryUserList");
        userList = getService4WebUI().querUserList(user, getPage());
        LOGGER.debug("exit query queryUserList");
        return SUCCESS;
    }

    /**
     * 方法描述： 跳转到添加用户界面
     * 
     * @return
     */
    public String toAddUser() {
        return SUCCESS;
    }

    /**
     * 方法描述：更新用户信息
     * 
     * @return
     */
    public String updateUser() {
        user = service4WebUI.updateUser(user);
        return SUCCESS;
    }

    /**
     * 方法描述： 跳转到更新页码
     * 
     * @return
     */
    public String toUpdateUser() {
        user = getService4WebUI().querUserByID(user.getUserID());
        return SUCCESS;
    }

    /**
     * 方法描述：添加用户（注册）
     * 
     * @return
     */
    public String addUser() {
        getService4WebUI().createUser(user);
        return SUCCESS;
    }

    public String delete() {
        getService4WebUI().deleteUser(user, false);
        return SUCCESS;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public User getUser() {
        return user;
    }

    public void setConfigurationManager(ConfigurationManager configurationManager) {
        this.configurationManager = configurationManager;
    }

    public ConfigurationManager getConfigurationManager() {
        return configurationManager;
    }

    public Service4WebUI getService4WebUI() {
        return service4WebUI;
    }

    public void setService4WebUI(Service4WebUI service4WebUI) {
        this.service4WebUI = service4WebUI;
    }

    /**
     * @return the userList
     */
    public List<User> getUserList() {
        return userList;
    }

    /**
     * @param userList
     *            the userList to set
     */
    public void setUserList(List<User> userList) {
        this.userList = userList;
    }

    /**
     * @return the page
     */
    public Page getPage() {
        return page;
    }

    /**
     * @param page
     *            the page to set
     */
    public void setPage(Page page) {
        this.page = page;
    }

}
